/*** Trigger Name: ifulfillRestrictEditWFunction 
 * Author: Accenture
 * Date: 10-feb-2012
 * Requirement/Project Name: iFulfill
 * Requirement Description: 
 **/


trigger ifulfillRestrictEditWFunction on Workflow_Stage__c ( before Update) 
{
list<Workflow_Definition__c> wdefinitionList = new list<Workflow_Definition__c>();
Set<ID> wfId = new Set<Id>();

 for(Workflow_Stage__c wfstageObj: trigger.new)
 {
     wfId.add(wfstageObj.Workflow_Code__c);
 }
 wdefinitionList =[Select Status__c from Workflow_Definition__c where id in :wfID and (Status__c = 'Inactive'or Status__c ='Pending Inactivation' ) ];
 
 wfId.clear();
 for(Workflow_Definition__c wfObj: wdefinitionList)
 {
     wfId.add(wfObj.id);
 }  
 
 for(Workflow_Stage__c wfstageObj: trigger.new)
 {
      // check if workflow is inactive or pending inactive status
      if(wfID.contains(wfstageObj.Workflow_Code__c))
      {
                wfstageObj.adderror('Cannot edit workflow function if assocaited Workflow is in Pending Inactive or Inactive status');          
      } 
 }
}